﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

/**
 * 泛型类
 */
namespace BiliBiliCSharpStudy.ch30.d04 {
    class HelloGeneric4 {
        public static void Demo() {
            Test1();
        }
        public static void Test1() {
            Apple apple = new Apple() { Color = "Red" };
            Book book = new Book() { Name = "笑傲江湖" };
            Box<Apple> box1 = new Box<Apple>() { Cargo = apple };
            Box<Book> box2 = new Box<Book>() { Cargo = book };
            Console.WriteLine(box1.Cargo.Color);
            Console.WriteLine(box2.Cargo.Name);
        }
    }

    class Apple {
        public string Color { get; set; }
    }

    class Book {
        public string Name { get; set; }
    }

    /**
     * `<TCargo>`叫作“泛型参数”
     */
    class Box<TCargo> {
        public TCargo Cargo { get; set; }
    }
}
